package settings

import (
	"encoding/json"

	"io/ioutil"
	"os"
)

type Setting struct {
	Rpc  string `json:"rpc"`
	Dsn  string `json:"dsn"`
	Port string `json:"port"`
}

var mSetting Setting

func Init(path string) error {

	fi, err := os.Open(path)
	if err != nil {
		return err
	}
	defer fi.Close()

	fd, err := ioutil.ReadAll(fi)
	if err != nil {
		return err
	}

	err = json.Unmarshal(fd, &mSetting)
	if err != nil {
		return err
	}

	return nil
}

func unInit() {
	mSetting = Setting{}
}
func GetDsn() string {
	return mSetting.Dsn
}

func GetRpc() string {
	return mSetting.Rpc
}

func GetPort() string {
	return mSetting.Port
}
